<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* CSS 样式 */
.download-section {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.download-header {
  text-align: center;
  margin-bottom: 2rem;
}

.year-filter {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.filter-btn {
  background: #f0f0f0;
  border: 2px solid #ddd;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s;
}

.filter-btn.active {
  background: #2196F3;
  color: white;
  border-color: #2196F3;
}

.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.download-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: transform 0.3s;
}

.download-card:hover {
  transform: translateY(-5px);
}

.year-tag {
  background: #FF6B6B;
  color: white;
  padding: 0.2rem 0.8rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.batch-download {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 2rem;
  border: 2px dashed #ddd;
}

.batch-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.batch-btn {
  background: #4CAF50;
  color: white;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 保持原有下载按钮样式，新增： */
.download-btn {
  width: 100%;
  margin-top: 1rem;
  position: relative;
  overflow: hidden;
}

.download-btn::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, 
    transparent 25%, 
    rgba(255,255,255,0.1) 50%, 
    transparent 75%);
  animation: shine 2s infinite;
}

@keyframes shine {
  to { transform: translateX(100%); }
}

@media (max-width: 768px) {
  .batch-info { flex-direction: column; }
  .download-grid { grid-template-columns: 1fr; }
}
/* 分享按钮样式 */
.share-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.share {
  position: relative;
  padding: 0.8rem 2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  background: #f5f5f5;
  color: #333;
}

.share::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-right: 0.8rem;
  background-size: contain;
  background-repeat: no-repeat;
}

.share.wechat::before {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%234CAF50" d="M9.5 4C5.36 4 2 6.69 2 10c0 1.89 1.39 3.57 3.5 4.55V16l3.44-1.88c.47.09.95.13 1.44.13 4.14 0 7.5-2.69 7.5-6s-3.36-6-7.5-6m0 10c-.62 0-1.22-.07-1.79-.2L5.8 14.5 7 12.81C5.19 12.12 4 11.04 4 10c0-2.5 2.46-4.5 5.5-4.5S15 7.5 15 10s-2.46 4.5-5.5 4.5m9.5 1.5c1.11 0 2.11.45 2.83 1.17L22 16v-1.23c0-1.64-1.69-3-3.78-3-1.07 0-2.06.32-2.83.86-.12.08-.25.15-.39.21.28.78.43 1.62.43 2.49 0 .18 0 .35-.03.53.15.03.3.03.45.03z"/></svg>');
}

.share.email::before {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%232196F3" d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z"/></svg>');
}

.share:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.share.wechat:hover {
  background: #E8F5E9;
  color: #2E7D32;
}

.share.email:hover {
  background: #E3F2FD;
  color: #1565C0;
}

/* 二维码弹窗样式 */
.qrcode-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.qrcode-content {
  background: white;
  padding: 2rem;
  border-radius: 12px;
  text-align: center;
}

.qrcode-content img {
  width: 200px;
  height: 200px;
  margin: 1rem 0;
}
    </style>
</head>
<body>
    <!-- HTML 结构 -->
<section class="download-section">
    <div class="download-header">
      <h2>MS Office 历年真题解析合集</h2>
      <div class="year-filter">
        <button class="filter-btn active" data-year="all">全部年份</button>
        <button class="filter-btn" data-year="2024">2024</button>
        <button class="filter-btn" data-year="2023">2023</button>
        <button class="filter-btn" data-year="2022">2022</button>
        <button class="filter-btn" data-year="2021">2021</button>
        <button class="filter-btn" data-year="2020">2020</button>
      </div>
    </div>
  
    <div class="download-grid">
      <!-- 单年文件模板 -->
      <div class="download-card" data-year="2024">
        <div class="card-header">
          <span class="year-tag">最新</span>
          <h3>2024真题解析</h3>
        </div>
        <div class="file-info">
          <div class="meta-item">
            <i class="icon">📅</i>
            <span>更新日期：2024-03-25</span>
          </div>
          <div class="meta-item">
            <i class="icon">📚</i>
            <span>包含6套最新真题</span>
          </div>
        </div>
        <button class="download-btn" data-file="2024">
          <span class="text">下载2024版</span>
          <span class="count" data-counter="2024">0次下载</span>
        </button>
      </div>
  
      <!-- 其他年份自动生成 -->
    </div>
  
    <!-- 批量下载面板 -->
    <div class="batch-download">
      <div class="batch-header">
        <h3>合集打包下载（2020-2024）</h3>
        <div class="tooltip">💡 包含所有年份真题+对比分析手册</div>
      </div>
      <div class="batch-info">
        <div class="size-info">
          <i class="icon">📦</i>
          <span>总大小：328MB（可分年下载）</span>
        </div>
        <button class="batch-btn">
          <span>一键下载完整合集</span>
          <span class="batch-count">已下载 <span id="totalCount">0</span> 次</span>
        </button>
      </div>
    </div>
    <!-- 增加社交分享 -->
    <div class="share-buttons">
        <button class="share wechat" data-share="wechat">微信分享</button>
        <button class="share email" data-share="email">邮件发送</button>
      </div>
  </section>
  <script>
    // JavaScript 交互
const downloadData = {
  "total": 0,
  "2024": { count: 0, url: '/2024.pdf' },
  "2023": { count: 0, url: '/2023.pdf' },
  "2022": { count: 0, url: '/2022.pdf' },
  "2021": { count: 0, url: '/2021.pdf' },
  "2020": { count: 0, url: '/2020.pdf' }
};

// 初始化数据
function initDownloads() {
  const savedData = localStorage.getItem('msOfficeDownloads');
  if(savedData) Object.assign(downloadData, JSON.parse(savedData));
  
  // 更新计数器
  document.querySelectorAll('[data-counter]').forEach(el => {
    const year = el.dataset.counter;
    el.textContent = `${downloadData[year].count}次下载`;
  });
  document.getElementById('totalCount').textContent = downloadData.total;
}

// 下载处理
function handleDownload(year) {
    // 在handleDownload函数中添加 添加文件预览功能
function showPreview(year) {
  const modal = document.createElement('div');
  modal.innerHTML = `
    <div class="preview-modal">
      <iframe src="/preview?year=${year}"></iframe>
    </div>
  `;
  document.body.appendChild(modal);
}
  const btn = document.querySelector(`[data-file="${year}"]`);
  btn.classList.add('downloading');
  
  setTimeout(() => {
    // 更新数据
    downloadData[year].count++;
    downloadData.total++;
    localStorage.setItem('msOfficeDownloads', JSON.stringify(downloadData));
    
    // 触发下载
    const link = document.createElement('a');
    link.href = downloadData[year].url;
    link.download = `MS-Office-${year}.pdf`;
    link.click();
    
    // 更新UI
    btn.querySelector('[data-counter]').textContent = 
      `${downloadData[year].count}次下载`;
    document.getElementById('totalCount').textContent = downloadData.total;
    btn.classList.remove('downloading');
  }, 1500);
}

// 年份筛选
document.querySelectorAll('.filter-btn').forEach(btn => {
  btn.addEventListener('click', function() {
    document.querySelectorAll('.filter-btn').forEach(b => 
      b.classList.remove('active'));
    this.classList.add('active');
    
    const year = this.dataset.year;
    document.querySelectorAll('.download-card').forEach(card => {
      card.style.display = (year === 'all' || card.dataset.year === year) 
        ? 'block' : 'none';
    });
  });
});

// 批量下载
document.querySelector('.batch-btn').addEventListener('click', () => {
  const years = ['2024','2023','2022','2021','2020'];
  years.forEach(year => {
    if(confirm(`是否要下载${year}年真题？`)) handleDownload(year);
  });
});

// 初始化
document.addEventListener('DOMContentLoaded', initDownloads);
// 记录下载时间
downloadData[year].lastDownload = new Date().toISOString();
// 分享功能实现
document.querySelectorAll('.share').forEach(button => {
  button.addEventListener('click', function() {
    const type = this.dataset.share;
    
    // 添加点击反馈
    this.style.transform = 'scale(0.95)';
    setTimeout(() => {
      this.style.transform = '';
    }, 200);

    switch(type) {
      case 'wechat':
        showWechatShare();
        break;
      case 'email':
        sendEmail();
        break;
    }
  });
});

// 微信分享功能
function showWechatShare() {
  const modal = document.createElement('div');
  modal.className = 'qrcode-modal';
  modal.innerHTML = `
    <div class="qrcode-content">
      <h3>扫码分享到微信</h3>
      <img src="./images/wechat-qrcode.png" alt="微信分享二维码">
      <p>打开微信扫一扫，分享给好友或朋友圈</p>
      <button onclick="this.parentElement.parentElement.remove()">关闭</button>
    </div>
  `;
  
  modal.addEventListener('click', (e) => {
    if(e.target === modal) modal.remove();
  });
  
  document.body.appendChild(modal);
  modal.style.display = 'flex';
}

// 邮件分享功能
function sendEmail() {
  const subject = 'MS Office历年真题资料分享';
  const body = `我发现这份优质的MS Office考试资料，推荐给你：\n\n${window.location.href}\n\n包含2020-2024年真题解析，助你轻松备考！`;
  window.location.href = `mailto:?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
  
  // 统计分享次数
  trackShareEvent('email');
}

// 分享统计（需要后端接口支持）
function trackShareEvent(platform) {
  fetch('/api/track-share', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      platform: platform,
      page: window.location.pathname
    })
  }).catch(error => console.error('Tracking error:', error));
}

// 微信环境检测
function isWechatBrowser() {
  return /MicroMessenger/i.test(navigator.userAgent);
}

// 自动隐藏微信按钮（可选）
if(!isWechatBrowser()) {
  document.querySelector('.share.wechat').style.display = 'none';
}
  </script>
    
</body>
</html>